<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use app\assets\CropperAsset;
use app\assets\TimelineAsset;
use app\assets\JqueryUIAsset;
use yii\widgets\Breadcrumbs;
use app\modules\clinical\models\Patient;
use app\models\Helpers;

/* @var $this yii\web\View */
/* @var $model app\models\Patient */
/* @var $form yii\widgets\ActiveForm */
$this->title = (empty($this->title)) ? '创建新患者' : $this->title;
$this->params['breadcrumbs'][] = ['label' => '临床信息', 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => '基本信息', 'url' => ['/clinical/patient']];
$this->params['breadcrumbs'][] = $this->title;

TimelineAsset::register($this);
CropperAsset::register($this);
JqueryUIAsset::register($this);
$this->registerCssFile("/css/cropper.css");
$this->registerJsFile("/js/pic.js?v=1", ['depends' => 'yii\web\JqueryAsset']);
$this->registerJsFile('@web/js/label.js', ['depends' => 'app\assets\JqueryUIAsset']);
$this->registerJsFile('@web/js/patient.js?v=1', ['depends' => 'app\assets\AppAsset']);

$pic = Helpers::checkExist("pt_family");
$optional = $model->clearRadio();

?>

<?= Breadcrumbs::widget([
  'homeLink' => ['label' => '医疗管理系统', 'url' => '#'],
  'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
]) ?>

<style type="text/css">
  .labels-div {min-width: 500px; max-width: 800px;}
  .labels-div div {float:left; margin-right: 5px; margin-bottom: 5px;}
  .label i {cursor: pointer;}
  .suggest {background-color: #fff; width: 800px; border: 1px solid #ccc;}
  .suggest div {font-size: 1.2em; margin: 5px 10px; cursor: pointer;}
  .addr {width: 500px;}
  .calendar-icon {width: 10px; display: inline;}
</style>

<div class="patient-form">

  <?php $form = ActiveForm::begin([
      'method' => 'post',
      'action' => $model->isNewRecord ? '/clinical/patient/create' : 'update?id='.$model->pk_id,
      'id' => 'PatientForm'
  ]); ?>
  <section class="cd-horizontal-timeline">
  <div class="timeline">
    <div class="events-wrapper">
      <div class="events">
        <ol id="timelineList">
          <li><a href="#0" data-date="basic" class="selected">基本信息</a></li>
          <li><a href="#0" data-date="medicine">疾病信息</a></li>
          <li><a href="#0" data-date="label">标签信息</a></li>
        </ol>

        <span class="filling-line" aria-hidden="true"></span>
      </div> <!-- .events -->
    </div> <!-- .events-wrapper -->
          
  </div> <!-- .timeline -->

  <div class="alert alert-danger" id="error-msg"></div>
  <div class="events-content myForm">
    <ol>
      <li class="selected" data-date="basic">

      <?= $form->field($model, 'pt_name')->textInput() ?>

      <?= $form->field($model, 'pt_id')->textInput() ?>

      <?= $form->field($model, 'dna_id')->textInput() ?><br />

      <?= $form->field($model, 'pt_sex')->dropDownList(Patient::getParams('sex')) ?>

      <?= $form->field($model, 'pt_birth')->textInput(['class'=>'form-control laydate-icon date']) ?>

      <?= $form->field($model, 'pt_marry')->dropDownList(Patient::getParams('marry')) ?>

      <?= $form->field($model, 'pt_customary')->dropDownList(Patient::getParams('customary')) ?><br />

      <?= $form->field($model, 'pt_nation')->dropDownList(Patient::getParams('nation')) ?>

      <?= $form->field($model, 'pt_edu')->dropDownList(Patient::getParams('edu')) ?>

      <?= $form->field($model, 'pt_vocation')->textInput(['maxlength' => true]) ?>

      <?= $form->field($model, 'pt_insu')->dropDownList(Patient::getParams('insurance')) ?><br />

      <?= $form->field($model, 'pt_addr')->textInput(['class' => 'addr form-control']) ?><br />

      <?= $form->field($model, 'rel_relation1')->dropDownList(Patient::getParams('relation')) ?>

      <?= $form->field($model, 'rel_phone1')->textInput(['maxlength' => true]) ?>

      <?= $form->field($model, 'rel_email1')->textInput(['maxlength' => true]) ?><br />

      <?= $form->field($model, 'rel_relation2')->dropDownList(Patient::getParams('relation')) ?>

      <?= $form->field($model, 'rel_phone2')->textInput(['maxlength' => true]) ?>

      <?= $form->field($model, 'rel_email2')->textInput(['maxlength' => true]) ?><br />

      <?= $form->field($model, 'pt_hsp')->textInput(['maxlength' => true]) ?>

      <?= $form->field($model, 'pt_intro')->textInput(['maxlength' => true]) ?>

      <?= $form->field($model, 'isCooperate')->radioList(Patient::getParams('yesno')) ?>

      </li>

      <li data-date="medicine">

      <?= $form->field($model, 'pt_disease')->radioList(Patient::getParams('disease')) ?>
      <input type="<?= ($optional['disease'] != '') ? 'text' : 'hidden' ?>" id="disease" name="Patient[pt_disease]" class="form-control" value="<?= $optional['disease'] ?>" <?= ($optional['disease'] != '') ? '' : 'disabled' ?> /><br />

      <?= $form->field($model, 'pt_history')->checkboxList(Patient::getParams('history'),['class' => 'checkBox']) ?><br />

      <?= $form->field($model, 'pt_fml')->radioList(Patient::getParams('youwu')) ?>

      <?= $form->field($model, 'pt_jinqin')->radioList(Patient::getParams('youwu')) ?>

      <?= $form->field($model, 'pt_dead')->radioList(['1'=>'是', '1001-01-01'=>'否']) ?>
      <input type="<?= ($optional['dead'] != '') ? 'text' : 'hidden' ?>" name="Patient[pt_dead]" class="form-control laydate-icon" id="pt_dead_date" value="<?= $optional['dead'] ?>" <?= ($optional['dead'] != '') ? '' : 'disabled' ?> />
      <br />

      <?= $form->field($model, 'pt_age')->textInput() ?>
      
      <div class="crop-avatar">
          <b>家系图：</b>
          <?= HTML::button('添加图片', ['class' => 'btn btn-default avatar-view']) ?>
          <?= HTML::a('查看图片', $pic['href'], ['class' => 'btn btn-default', 'target' => '_blank']) ?>
          <input type="hidden" id="pic-name" value="pt_family">
          <img <?= $pic['name'] ?> id="upload-pic">
      </div>

      </li>

      <li data-date="label">
      
      <b>添加标签：</b><br /><br />
      <div class="labels-div">
          <?= Html::hiddenInput('Patient[pt_label]', $model->pt_label, ['id' => 'patient-pt_label']) ?>
      </div>
      <?= Html::input('text', 'label', '', ['class' => 'form-control mb-input']) ?><br />
      <?= $form->field($model, 'pt_note')->textArea() ?><br />

      </li>
    </ol>

  </div> <!-- .events-content -->
  </section>

  <input type="hidden" id="status" value="<?= $model->isNewRecord ? 'create' : 'update?id='.$model->pk_id ?>">
  <div class="form-group active">
      <?= Html::submitButton($model->isNewRecord ? '保存' : '更新', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary', 'id' => 'submitButton']) ?>

      <?= Html::a('取消', 'index', ['class' => 'btn btn-success']) ?>
  </div>
  
  <?php ActiveForm::end(); ?>

  <div class="crop-avatar">
      <?= $this->render('@app/views/layouts/media.php') ?>
  </div>

</div>

<?php if ($optional['dead'] != '') :?>
<?php $this->beginBlock('layer') ?>
    $("input[name='Patient[pt_dead]'][type='date']").val("<?= $optional['dead'] ?>");
<?php $this->endBlock() ?>
<?php $this->registerJs($this->blocks['layer'], \yii\web\View::POS_END); ?>
<?php endif;?>
